from utils.data_load import dataload
from utils.feature_engineering import feature_engineering
from sklearn.linear_model import LogisticRegression
import joblib, os

def train_model():
    # 1. 数据加载
    X_train, X_test, y_train, y_test = dataload()

    # 2. 特征工程
    X_train, X_test,y_train = feature_engineering(X_train, X_test,y_train)

    # 3. 模型训练
    lr = LogisticRegression(max_iter=1000, random_state=22)
    lr.fit(X_train, y_train)

    # 4. 模型保存
    os.makedirs("../model", exist_ok=True)
    model_path = "../model/logistic_regression_model.pkl"
    joblib.dump(lr, model_path)
    print(f"✅ 模型已保存至: {model_path}")

if __name__ == "__main__":
    train_model()
